//
//  Setting_InviteColleagueViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 16/9/18.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Setting_InviteColleagueViewController.h"

#import "Setting_InviteColleagueTableViewCell.h"
#import <MessageUI/MessageUI.h>

@interface Setting_InviteColleagueViewController () <UITableViewDelegate, UITableViewDataSource,MFMessageComposeViewControllerDelegate>

@property (nonatomic, strong) UITableView * tableView;

@end

@implementation Setting_InviteColleagueViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"邀请同事";
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 35, 15)];
    lbl_return.text = @"返回";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 60, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[Setting_InviteColleagueTableViewCell class] forCellReuseIdentifier:@"InviteColleague"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Setting_InviteColleagueTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"InviteColleague" forIndexPath:indexPath];
    
    switch (indexPath.row)
    {
        case 0:
        {
            cell.image_icon.image = [UIImage imageNamed:@"invite_weixin.png"];
            cell.lbl_name.text = @"微信";
        }
            break;
        case 1:
        {
            cell.image_icon.image = [UIImage imageNamed:@"invite_message.png"];
            cell.lbl_name.text = @"短信";
        }
            break;
        case 2:
        {
            cell.image_icon.image = [UIImage imageNamed:@"invite_mail.png"];
            cell.lbl_name.text = @"邮箱";
        }
            break;
        case 3:
        {
            cell.image_icon.image = [UIImage imageNamed:@"invite_copy.png"];
            cell.lbl_name.text = @"复制邀请链接";
            cell.lbl_detail.text = @"邀请信文本复制";
        }
            break;
        default:
            break;
    }
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row)
    {
        case 0:
        {
            NSLog(@"调用友盟，分享给好友");
        }
            break;
        case 1:
        {//短信发送
            MFMessageComposeViewController *smsController = [[MFMessageComposeViewController alloc] init];
            smsController.messageComposeDelegate = self;
            
            //可以写一个方法专门组复杂的字符串在这调用即可
            [smsController setBody:@"XX邀请您加入【XXXXXXXXXXXX】，请店家链接【http://xxxxxxxx】完成注册，该链接24小时内有效。【XXXX】"];
            
            [self presentViewController:smsController animated:YES completion:^{
            }];
        }
            break;
        case 2:
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://"]];
        }
            break;
        case 3:
        {
            [UIPasteboard generalPasteboard].string = @"XX邀请您加入【XXXXXXXXXXXX】，请店家链接【http://xxxxxxxx】完成注册，该链接24小时内有效。【XXXX】";
            
            [SVProgressHUD setMinimumDismissTimeInterval:0.9f];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
            [SVProgressHUD setBackgroundColor:[UIColor grayColor]];
            [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
            [SVProgressHUD showSuccessWithStatus:@"复制成功"];
        }
            break;
        default:
            break;
    }
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    
    //比如这里只要求让短信界面消失，不做其他处理
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}
















@end
